package com.third.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.third.entity.InboundOrder;
import com.third.entity.Quality;
import com.third.entity.R;
import com.third.entity.Result;
import com.third.mapper.InBoundMap;
import com.third.mapper.InBoundMapper;
import com.third.mapper.QualityMap;
import com.third.mapper.QualityMapper;
import com.third.service.InBoundService;
import com.third.service.QualityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;

/**
 * @author 唐燈
 * @version 1.1
 * @date 2023/10/29 21:44
 */
@CrossOrigin(methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE})
@RequestMapping("/quality")
@RestController
public class Quality_Controller {


    @Autowired
    QualityMapper qualityMapper;

    @Autowired
    QualityService qualityService;

    @Autowired
    QualityMap qualityMap;

    //分页查询操作的实现
    @PostMapping("/list")
    public R getList(@RequestBody HashMap<String,Object> map){
        int count = (int) qualityService.count();
        int current =(int) map.get("current");
        int size =(int) map.get("size");
        int start=(current-1)*size;
        map.put("start",start);
        IPage<Quality> list = qualityService.getList(map);
        list.setTotal(count);
        return new R(true,list);
    }
    //添加质检单
    @PostMapping("/add")
    public Result add(@RequestBody Quality quality){
        qualityMap.insert(quality);
        return Result.success();
    }


    @PutMapping("/update")
    public Result update(@RequestBody Quality quality){
        qualityMap.update(quality);
        return Result.success();
    }

    @DeleteMapping("/delete")
    public Result delete(@RequestParam Integer testId){
        System.out.println("1008601");
        qualityMap.delete(testId);
        return Result.success();
    }
}
